package org.jtf.servlet;

import com.jtf.ignite.test.ejbs.cache.CacheService;
import com.jtf.ignite.test.ejbs.cache.impl.CacheServiceImpl;

import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/test")
public class TestServlet extends HttpServlet {

//    @EJB(name = "CacheService")
//    @Resource(lookup = "java:app/ejbs-1.0-SNAPSHOT/CacheService")
//    @Resource(lookup = "java:module/CacheService")
    @EJB
CacheService cacheService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String key = req.getParameter("key");
        String value = req.getParameter("value");
        if(value!=null){
            cacheService.setTestCache(key, value);
            resp.getWriter().println("success");
            return;
        }else {
            value = cacheService.getTestCache(key);
            resp.getWriter().println(value);
            return;
        }
    }
}
